/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.siagefi.service;

import br.siagefi.dao.DAO;
import br.siagefi.model.ClientePF;
import br.siagefi.model.Documento;
import br.siagefi.model.NotaFiscal;
import java.util.List;

/**
 *
 * @author NOTE
 */
public class ClientePFService {
   private final DAO<ClientePF> dao;

    public ClientePFService() {
        this.dao = new DAO<>(ClientePF.class);
    }
    
    public void inserir(ClientePF clientePF){
        dao.adiciona(clientePF);
    }
    
    public void alterar(ClientePF clientePF){
        dao.atualiza(clientePF);
    }
    
    public List<ClientePF> listar(){
        return dao.listaTodos();
    }
    
    public void remover(ClientePF clientePF){
        dao.remove(clientePF);
    }
    
    public boolean jaExiste(ClientePF clientePF) {
        List<ClientePF> lista = this.listar();
        for (ClientePF c : lista) 
            if(c.equals(clientePF))
                return true;
        return false;
    }
    
    public ClientePF listarPorCPF(String cpf) {
        List<ClientePF> lista = dao.consultar("ClientePF.buscaPorCPF", cpf);
        if(! lista.isEmpty()){
            return lista.get(0);
        }else {
            return null;
        }
    }
    
    public boolean existeDocumentoVinculado(ClientePF clientePF) {
        return !(new DAO<>(Documento.class).consultar("Documento.buscaPorPessoa", clientePF).isEmpty());
    }

    public boolean existeNotaFiscalVinculada(ClientePF clientePF) {
        return !(new DAO<>(NotaFiscal.class).consultar("NotaFiscal.buscaPorCliente", clientePF).isEmpty());
    }
}
